package com.baizhi.cmfzmanager.controller;

import com.baizhi.cmfzmanager.entity.Banner;
import com.baizhi.cmfzmanager.service.BannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class BannerController {
    @Autowired
    private BannerService bannerService;

    @RequestMapping("/showBanners.do")
    public Map getBanners(int page,int rows){

        return bannerService.getBanners(page,rows);
    }

    @RequestMapping("/addBanner.do")
    public Map addBanner(Banner banner){
        Map map=new HashMap();
        try {
            bannerService.addBanner(banner);
            map.put("isAdd",true);
        } catch (Exception e) {
            map.put("isAdd",false);
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return map;
    }


    @RequestMapping("/updateBanner.do")
    public Map updateBanner(Banner banner){
        Map map=new HashMap();
        try {
            bannerService.updateBanner(banner);
            map.put("isUpdate",true);
        } catch (Exception e) {
            map.put("isUpdate",false);
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return map;
    }

    @RequestMapping("/deleteBanner.do")
    public void deleteBanner(int[] id){
        bannerService.deleteBanner(id);
    }

}
